Repository navigation
Formatting: Avoid nested links in make_clickable() when link text has surrounding content - #16264
ankit-addweb wants to merge 2 commits into
Conversation
…as surrounding content. The final cleanup in `make_clickable()` only removed an accidental link inside a link when the nested link was the sole content of the outer link. Any text around it, even whitespace, left output like `<a href="..."> <a href="..." rel="nofollow">...</a></a>`. The cleanup now keeps text before and after the nested link, limited to a single outer link so adjacent links are left untouched. See #50514.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
|
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
Trac ticket: https://core.trac.wordpress.org/ticket/50514
Problem
The last step of
make_clickable()removes accidental links inside links, but only when the nested link is the sole content of the outer link. If there is any text around it, even whitespace, the nested link stays:Fix
The cleanup regex now keeps text before and after the nested link (
[^<]*on each side). Limiting it to non-tag characters keeps the match inside one outer link, so adjacent links are not merged. This avoids the problem with the greedy(.+)?approach noted on the ticket, where two adjacent links still produced nested output.Testing
New tests in
makeClickable.phpcover whitespace before and after the URL, text on both sides, a newline, two adjacent links, and two links separated by text.formattinggroup has no failures.phpcsis clean on both files.Related: #19028, #20418, #3228. This supersedes the approach in #371, which has the adjacent-link problem described above.